package com.suxin.shiro.web;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author Tang
 * @classname UserController
 * @description [  ]
 * @date 2021/3/21 11:41
 */
//@RestController
//@RequestMapping("/user")
public class UserController {

    @GetMapping("/login")
    public String login(String username,String password) {
        Subject subject = SecurityUtils.getSubject();
        try {
            subject.login(new UsernamePasswordToken(username,password));
        } catch (Exception e) {
            return "fail...";
        }
        return "login success...";
    }

    @GetMapping("/logOut")
    public String logOut() {
        Subject subject = SecurityUtils.getSubject();
        subject.logout();
        return "logOut success...";
    }

    @RequiresRoles(value = {"admin"})
    @GetMapping("/userInfo")
    public String userInfo() {
        return "userInfo...";
    }

    @GetMapping("/error")
    public String loginError() {
        return "loginError...";
    }

}